<!--
 * @Author: YiFreerFiY
 * @Date: 2022-04-27 16:29:56
 * @Description:
 *
-->
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>

<body>
    <script type="text/javascript">
        var tribonacci = function(n) {
            if (n === 0) {
                return 0;
            }
            if (n <= 2) {
                return 1;
            }
            let p = 0,
                q = 0,
                r = 1,
                s = 1;
            for (let i = 3; i <= n; ++i) {
                p = q;
                q = r;
                r = s;
                s = p + q + r;
            }
            return s;
        };
        document.write(tribonacci(0));
    </script>
</body>

</html>
<!--

			var tribonacci = function(n) {
				if (n == 0) return 0;
				if (n < 3) return 1;
				let tri = [0, 1, 1];
				for (var i = 3; i <= n; i++) {
					tri[i % 3] = tri[0] + tri[1] + tri[2];
					// document.write(tri[i % 3]);
				}
				return tri[(i-2)%3];
			};
			// 0 1 1 2 4 7
			document.write(tribonacci(6));
			// document.write(tem); -->